<%--                                                                       --%>
<%-- Copyright (c) 2004-2005 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<%
  String ctxPath = request.getContextPath();
%>
<c:set var="searchType">
<%= request.getParameter("searchType") %>
</c:set>
<c:set var="sType">
<%= request.getParameter("searchType") %>
</c:set>
<c:set var="searchName">
<%= request.getParameter("name") %>
</c:set>

<script language="JavaScript">

function doPortletEditEntity(portletEntityId) {
  var action = '<c:url value="/ep/portletEntityEdit.do"/>';
  if (action.indexOf("?") == -1) {
    action += "?";
  }
  action += "programId=" + portletEntityId;

  document.portletSearchForm.action = action;
  document.portletSearchForm.submit();
}

function doPortletDeleteEntity(portletEntityId) {
  if (confirm('<bean:message key="ep.portlet.alert.confirmDeletePortletEntity" bundle="ep.messages"/>')) {
    var action = '<c:url value="/ep/portletEntitySearchDelete.do"/>';
    if (action.indexOf("?") == -1) {
      action += "?";
    }
    action += "programId=" + portletEntityId;
    action += "&searchType=" + <c:out value="${sType}"/>;
    action += "&name=" + '<c:out value="${searchName}"/>';
    
    document.portletSearchForm.action = action;
    document.portletSearchForm.submit();
  }
}

function doPortletAppDelete(portletAppId,serverId) {
  if (confirm('<bean:message key="ep.portlet.alert.confirmDeletePortletApp" bundle="ep.messages"/>')) {
    var action = '<c:url value="/ep/portletAppDelete.do"/>';
    if (action.indexOf("?") == -1) {
      action += "?";
    }
    action += "portletAppId=" + portletAppId;
    action += "&serverId=" + serverId;

    document.portletSearchForm.action = action;
    document.portletSearchForm.submit();
  }
}

function doPortletAppViewPortlets(portletAppId,serverId) {
  var action = '<c:url value="/ep/portletBrowse.do"/>';
  if (action.indexOf("?") == -1) {
    action += "?";
  }
  action += "portletAppId=" + portletAppId;
  action += "&serverId=" + serverId;

  document.portletSearchForm.action = action;
  document.portletSearchForm.submit();
}

function doPortletAppReinstall(portletAppId,serverId) {
  var action = '<c:url value="/ep/portletInstall.do"/>';
  if (action.indexOf("?") == -1) {
    action += "?";
  }
  action += "portletAppId=" + portletAppId + "&portletappaction=reinstall";
  action += "&serverId=" + serverId;
  
  document.portletSearchForm.action = action;
  document.portletSearchForm.submit();
}

function doPortletCreateEntity(portletId,portletAppId,serverId) {
  var action = '<c:url value="/ep/portletEntityNew.do"/>';
  if (action.indexOf("?") == -1) {
    action += "?";
  }
  action += "portletAppId=" + portletAppId;
  action += "&portletId=" + portletId;
  action += "&serverId=" + serverId;
  action += "&name=";

  document.portletSearchForm.action = action;
  document.portletSearchForm.submit();
}

function doPortletViewEntities(portletId,portletAppId,serverId) {
  var action = '<c:url value="/ep/portletEntityList.do"/>';
  if (action.indexOf("?") == -1) {
    action += "?";
  }
  action += "portletAppId=" + portletAppId;
  action += "&portletId=" + portletId;
  action += "&serverId=" + serverId;

  document.portletSearchForm.action = action;
  document.portletSearchForm.submit();
}

function doPortletEntitySetStatus(status, portletEntityId) {
  var action = '<c:url value="/ep/portletEntitySearchSetStatus.do"/>';
  if (action.indexOf("?") == -1) {
    action += "?";
  }
  action += "programId=" + portletEntityId;
  action += "&status=" + status;
  
  document.portletSearchForm.action = action;
  document.portletSearchForm.submit();
}

function checkRequiredFields(form) {  
  if(form.searchType.selectedIndex==0) {
    alert('<bean:message key='ep.alert.no.search.type.selected' bundle="ep.messages"/>');
    return false;
  }
  return true;
}

<%@ include file="/mc/common/jsutils.jsp" %>

</script>

<c:set var="editImg">
<img src="<%= ctxPath %>/ep/images/action/icon_edit.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean:message key="image.alt.edit" bundle="ep.messages"/>" title="<bean:message key="image.alt.edit" bundle="ep.messages"/>">
</c:set>
<c:set var="deleteImg">
<img src="<%= ctxPath %>/ep/images/action/icon_delete.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean:message key="image.alt.delete" bundle="ep.messages"/>" title="<bean:message key="image.alt.delete" bundle="ep.messages"/>">
</c:set>
<c:set var="reinstallImg">
<img src="<%= ctxPath %>/ep/images/action/icon_resume.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean:message key="image.alt.reinstall" bundle="ep.messages"/>" title="<bean:message key="image.alt.reinstall" bundle="ep.messages"/>">
</c:set>
<c:set var="viewImg">
<img src="<%= ctxPath %>/ep/images/action/icon_view.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean:message key="image.alt.view.portlets" bundle="ep.messages"/>" title="<bean:message key="image.alt.view.portlets" bundle="ep.messages"/>">
</c:set>
<c:set var="addImg">
<img src="<%= ctxPath %>/ep/images/action/icon_createnew.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean:message key="image.alt.create.entity" bundle="ep.messages"/>" title="<bean:message key="image.alt.create.entity" bundle="ep.messages"/>">
</c:set>
<c:set var="offlineImg">
<img src="<%= ctxPath %>/ep/images/action/icon_offline.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean:message key="image.alt.setOffline" bundle="ep.messages"/>" title="<bean:message key="image.alt.setOffline" bundle="ep.messages"/>">
</c:set>
<c:set var="onlineImg">
<img src="<%= ctxPath %>/ep/images/action/icon_online.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean:message key="image.alt.setOnline" bundle="ep.messages"/>" title="<bean:message key="image.alt.setOnline" bundle="ep.messages"/>">
</c:set>

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
    <td valign="top" width="100%">
      <div class="pageTitle">
      <bean:message key="ep.portlets.manage.page.title" bundle="ep.messages"/>
      <logic:present name="list">
        <bean-el:message key="ep.portlets.search.results.title" arg0="${pager.map.count}" bundle="ep.messages"/>
      </logic:present>
      </div>
      <div class="errorMessage"><html:errors/></div>
      <div>
      <%@include file="/mc/common/pagetab.jsp" %>
      </div>

<html:form action="/ep/portletAppSearch.do" onsubmit="return checkRequiredFields(this);">
<input type="hidden" name="contextPath" value="<c:out value="${ctxPath}"/>">

      <div class="pageSubtitle">
        <span class="left"><bean:message key="ep.search.criteria" bundle="ep.messages"/></span>
      </div>

      <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0" summary="Search criteria">

        <tr>
          <td class="label" width="30%">
            <bean:message key="ep.label.searchType" bundle="ep.messages"/>:*
          </td>
          <td class="labelField" width="70%" colspan="2">
            <html:select property="searchType" size="1">
              <html:option value="-1"><bean:message key="ep.label.select" bundle="ep.messages"/></html:option>
              <html:option value="0"><bean:message key="ep.label.portletApp" bundle="ep.messages"/></html:option>
              <html:option value="1"><bean:message key="ep.label.portlet" bundle="ep.messages"/></html:option>
              <html:option value="2"><bean:message key="ep.label.portletEntity" bundle="ep.messages"/></html:option>
            </html:select>
          </td>
        </tr>

        <tr>
          <td class="label" width="30%">
            <bean:message key="ep.label.name" bundle="ep.messages"/>:
          </td>
          <td class="labelField" width="70%" colspan="2">
            <html:text property="name" maxlength="80" size="31"/>
          </td>
        </tr>

      </table>

      <div class="pageButtonWrap" align="right">
        <input hspace="40" type="submit" name="actionSearch" class="pageButton" value="<bean:message key="button.showResults" bundle="ep.messages"/>">
      </div>

</html:form>

      <br>

<logic:present name="list">

      <div class="pageSubtitle">
      <span class="left"><bean-el:message key="ep.label.search.results" arg0="${pager.map.count}" bundle="ep.messages"/></span>

      <span class="right">
      </span>
      </div>

      <div class="pageInstructions">
      </div>

<c:if test="${searchType == 0}">      
      <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Search result table" width="100%">
        <tr class="listHeader">
          <th id="Name" align="left"><bean:message key="ep.header.name.portlet.app" bundle="ep.messages"/></th>
          <th id="Producer" align="left"><bean:message key="ep.header.name.producer" bundle="ep.messages"/></th>
          <th id="Actions" align="left" nowrap><bean:message key="ep.header.actions" bundle="ep.messages"/></th>
        </tr>

        <!-- results -->

<logic:iterate id="item" name="list" indexId="index">
        <tr class="<%= index.intValue() % 2 == 0 ? "listEven" : "listOdd" %>">
          <c:url var="browseUrl" value="/ep/portletBrowse.do">
            <c:param name="portletAppId" value="${item.map.id}"/>
            <c:param name="serverId" value="${item.map.serverId}"/>
	  </c:url>

          <td headers="Name"><a href="<c:out value="${browseUrl}"/>"><bean:write
            name="item" property="id"/></a></td>
          <td headers="Producer"><bean:write name="item" property="producerName"/></td>
          <td headers="Actions">
            <a href="#" onclick="doPortletAppReinstall('<c:out value="${item.map.id}"/>',<c:out value="${item.map.serverId}"/>);"><c:out
            value='${reinstallImg}' escapeXml="false"/></a>
            <a href="#" onclick="doPortletAppViewPortlets('<c:out value="${item.map.id}"/>',<c:out value="${item.map.serverId}"/>);"><c:out
            value='${viewImg}' escapeXml="false"/></a>
            <a href="#" onclick="doPortletAppDelete('<c:out value="${item.map.id}"/>',<c:out value="${item.map.serverId}"/>);"><c:out
            value='${deleteImg}' escapeXml="false"/></a>
          </td>
        </tr>
</logic:iterate>

      </table>
</c:if>

<c:if test="${searchType == 1}">
      <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Search result table" width="100%">
        <tr class="listHeader">
          <th id="Name" align="left"><bean:message key="ep.header.name.portlet" bundle="ep.messages"/></th>
          <th id="Producer" align="left"><bean:message key="ep.header.name.producer" bundle="ep.messages"/></th>
          <th id="Description" alight="left"><bean:message key="ep.header.description" bundle="ep.messages"/></th>
          <th id="Actions" align="left" nowrap><bean:message key="ep.header.actions" bundle="ep.messages"/></th>
        </tr>

        <!-- results -->

<logic:iterate id="item" name="list" indexId="index">
        <tr class="<%= index.intValue() % 2 == 0 ? "listEven" : "listOdd" %>">
          <c:url var="browseUrl" value="/ep/portletEntityList.do">
            <c:param name="portletId" value="${item.map.id}"/>
            <c:param name="portletAppId" value="${item.map.portletAppDefId}"/>
            <c:param name="serverId" value="${item.map.serverId}"/>
	  </c:url>
          <td headers="Name"><a href="<c:out value="${browseUrl}"/>"><bean:write
            name="item" property="id"/></a></td>
          <td headers="Producer"><bean:write name="item" property="producerName"/></td>
          <td headers="Description"><bean:write name="item" property="description"/></td>
          <td headers="Actions">
            <a href="#" onclick="doPortletCreateEntity('<c:out value="${item.map.id}"/>','<c:out value="${item.map.portletAppDefId}"/>',<c:out value="${item.map.serverId}"/>);"><c:out
            value='${addImg}' escapeXml="false"/></a>
            <a href="#" onclick="doPortletViewEntities('<c:out value="${item.map.id}"/>','<c:out value="${item.map.portletAppDefId}"/>',<c:out value="${item.map.serverId}"/>);"><c:out
            value='${viewImg}' escapeXml="false"/></a>
          </td>
        </tr>
</logic:iterate>

      </table>

</c:if>

<c:if test="${searchType == 2}">      
      <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Search result table" width="100%">
        <tr class="listHeader">
          <th id="Name" align="left"><bean:message key="ep.header.name.portlet.entity" bundle="ep.messages"/></th>
          <th id="Producer" align="left"><bean:message key="ep.header.name.producer" bundle="ep.messages"/></th>
          <th id="LastModifiedDate" align="left"><bean:message key="ep.header.lastModifiedDate" bundle="ep.messages"/></th>
          <th id="Actions" align="left" nowrap><bean:message key="ep.header.actions" bundle="ep.messages"/></th>
        </tr>

        <!-- results -->

<logic:iterate id="item" name="list" indexId="index">
        <tr class="<%= index.intValue() % 2 == 0 ? "listEven" : "listOdd" %>">
          <td headers="Name"><html:link page="/ep/portletEntityView.do"
            paramId="programId" paramName="item" paramProperty="id"><bean:write
            name="item" property="name"/></html:link></td>
          <td headers="Producer"><bean:write name="item" property="producerName"/></td>
          <td headers="LastModifiedDate">
            <bean:write name="item" property="lastModifiedDate"
                   formatKey="format.datetime.short" bundle="mc.messages"/>
          </td>
          <td headers="Actions">
            <a href="#" onclick="doPortletEditEntity('<c:out value="${item.map.id}"/>');"><c:out
            value='${editImg}' escapeXml="false"/></a>
            <c:choose>
              <c:when test="${item.map.status == 0}">
              <a href="#" onclick="doPortletEntitySetStatus(1, '<c:out value="${item.map.id}"/>');"><c:out
              value='${onlineImg}' escapeXml="false"/></a>
              </c:when>
              <c:otherwise>
              <a href="#" onclick="doPortletEntitySetStatus(0, '<c:out value="${item.map.id}"/>');"><c:out
              value='${offlineImg}' escapeXml="false"/></a>
              </c:otherwise>
            </c:choose>
            <a href="#" onclick="doPortletDeleteEntity('<c:out value="${item.map.id}"/>');"><c:out
            value='${deleteImg}' escapeXml="false"/></a>
          </td>
        </tr>
</logic:iterate>

      </table>
</c:if>
      <!-- pagination -->
<%@ include file="/mc/common/pager.jsp" %>
</logic:present>

    </td>
  </tr>
</table>
